package com.bilin.coin.list;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bilin.coin.R;
import com.bilin.coin.bean.DigToolsBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.utils.DensityUtils;
import com.bilin.coin.utils.GsonUtil;
import com.bilin.coin.utils.MoneyUtils;
import com.bilin.coin.utils.SpacesItemDecoration;
import com.bilin.coin.widget.AbsPullToRefreshRecycleView;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class DigToolsList extends AbsPullToRefreshRecycleView<DigToolsBean.RecordsBean> {


    public DigToolsList(BaseAppCompatActivity activity) {
        super(activity, true, false, true);
    }

    @Override
    public int fillPageSize() {
        return 15;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public List parseListDataAndFillTotal(String dataJson) {
        DigToolsBean digToolsBean = GsonUtil.GsonToBean(dataJson, DigToolsBean.class);
        totalCount = digToolsBean.getTotal();
        return digToolsBean.getRecords();
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage", page + "");
        params.put("pageSize", pageSize + "");
        return params;
    }

    @Override
    protected RecyclerView.LayoutManager fillLayoutManger() {
        LinearLayoutManager manager = new LinearLayoutManager(activity);
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.addItemDecoration(new SpacesItemDecoration(1, DensityUtils.dp2px(activity, 10), 0x1888));
        return manager;
    }

    @Override
    public String fillUrl() {
        return "/api/hold/list";
    }

    @Override
    protected void convertItem(BaseViewHolder helper, DigToolsBean.RecordsBean item) {
        //哪种设备 0：铁锹,1：推车A,2：推车B,3：小挖机,4：运煤车,5：大挖机

        switch (item.getType()) {
            case 0:
                helper.setText(R.id.tv_name, "铁锹 x"+item.getNum());
                break;
            case 1:
                helper.setText(R.id.tv_name, "推车A x"+item.getNum());
                break;
            case 2:
                helper.setText(R.id.tv_name, "推车B x"+item.getNum());
                break;
            case 3:
                helper.setText(R.id.tv_name, "小挖机 x"+item.getNum());
                break;
            case 4:
                helper.setText(R.id.tv_name, "运煤车 x"+item.getNum());
                break;
            case 5:
                helper.setText(R.id.tv_name, "大挖机 x"+item.getNum());
                break;
        }
        helper.setText(R.id.tv_rate, "速率："+ MoneyUtils.toPercent(new BigDecimal(item.getRate())));
    }

    @Override
    protected int fillAnimationType() {
        return BaseQuickAdapter.ALPHAIN;
    }

    @Override
    protected int fillItemLayout() {
        return R.layout.item_dig_tools;
    }
}
